import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/tabbar/category/controller.dart';
import 'package:flutter_jd/routes/routing_constants.dart';
import 'package:flutter_jd/ui/widgets/kit.dart';
import 'package:flutter_jd/ui/widgets/search/search_bar.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

// 搜索栏
class CategoryTopBar extends GetWidget<CategoryController> {
  final Map? arguments;

  CategoryTopBar({this.arguments});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 40.h,
      padding: EdgeInsets.only(right: 10.w, bottom: 5.h),
      color: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            width: 35.w,
            child: _buildHeadLeftBtn(),
          ),
          SearchBar(
            placeholderText: '机械键盘',
            background: Color(0xFFF6F6F6),
          ),
          Row(
            children: [
              GestureDetector(
                onTap: () {
                  Get.toNamed(MessageRoute);
                },
                child: Container(
                  color: Colors.transparent,
                  padding: EdgeInsets.only(left: 10.w),
                  child: Kit.iconFont(0xe8b8, Color(0xFF999999), 22.sp),
                ),
              )
            ],
          ),
        ],
      ),
    );
  }

  // 构建头部按钮
  Widget _buildHeadLeftBtn() {
    if (arguments!['back']) {
      return GestureDetector(
        onTap: () {
          Get.back();
        },
        child: Container(
          width: double.infinity,
          height: double.infinity,
          color: Colors.transparent,
          child: Kit.iconFont(0xe671, Color(0xFF333333), 18.sp),
        ),
      );
    } else {
      return Kit.iconFont(0xe8b6, Color(0xFF999999), 19.sp);
    }
  }
}
